mcnemar_tables: contingency tables for McNemar's test and Cochran's Q test
返り値は辞書
ここの分割表を #マクネマー検定 で使う、または、Cochran's Q Test code:example1.py
>> import numpy as np
>> from mlxtend.evaluate import mcnemar_tables
>> y_mod0 = np.array(0, 1, 0, 0, 0, 1, 1, 0, 0, 0) # 正, 誤, 正, 正, 正, 正, 正, 誤, 誤, 誤 >> y_mod1 = np.array(0, 0, 1, 1, 0, 1, 1, 0, 0, 0) # 正, 正, 誤, 誤, 正, 正, 正, 誤, 誤, 誤 >> tb = mcnemar_tables(y_true, y_mod0, y_mod1)
>> tb
{'model_0 vs model_1': array([4., 2., code:example2.py
>> import numpy as np
>> from mlxtend.evaluate import mcnemar_tables
>> y_mod0 = np.array(0, 1, 0, 0, 0, 1, 1, 0, 0, 0) # 正, 誤, 正, 正, 正, 正, 正, 誤, 誤, 誤 >> y_mod1 = np.array(0, 0, 1, 1, 0, 1, 1, 0, 0, 0) # 正, 正, 誤, 誤, 正, 正, 正, 誤, 誤, 誤 >> y_mod2 = np.array(0, 0, 1, 1, 0, 1, 1, 0, 1, 0) # 正, 正, 誤, 誤, 正, 正, 正, 誤, 正, 誤 >> tb = mcnemar_tables(y_true, y_mod0, y_mod1, y_mod2)
>> for key, value in tb.items():
... print(key)
... print(value)
... print()
...
model_0 vs model_1 # example1と同じ
model_0 vs model_2
model_1 vs model_2
code:docstring_example.py
>> y_mod0 = np.array(0, 1, 0, 0, 0, 1, 1, 0, 0, 0) # 正, 誤, 正, 正, 正, 正, 正, 誤, 誤, 誤 >> y_mod1 = np.array(0, 0, 1, 1, 0, 1, 1, 0, 0, 0) # 正, 正, 誤, 誤, 正, 正, 正, 誤, 誤, 誤 >> y_mod2 = np.array(0, 1, 1, 1, 0, 1, 0, 0, 0, 0) # 正, 誤, 誤, 誤, 正, 正, 誤, 誤, 誤, 誤 >> tb = mcnemar_tables(y_true, y_mod0, y_mod1, y_mod2)
>> for key, value in tb.items():
... print(key)
... print(value)
... print()
...
model_0 vs model_1 # example1と同じ
model_0 vs model_2 # model 2だけが正解しているところがない
model_1 vs model_2
code:unit_test_example.py
>> y_model0 = np.array(0, 1, 0, 0, 0, 1, 1, 0, 0, 0) # 正, 誤, 正, 正, 正, 正, 正, 誤, 誤, 誤 >> y_model1 = np.array(0, 0, 1, 1, 0, 1, 1, 0, 0, 0) # 正, 正, 誤, 誤, 正, 正, 正, 誤, 誤, 誤 >> y_model2 = np.array(0, 1, 1, 0, 0, 1, 1, 0, 0, 0) # 正, 誤, 誤, 正, 正, 正, 正, 誤, 誤, 誤 >> tb = mcnemar_tables(y_target, y_model0, y_model1, y_model2)
>> for key, value in tb.items():
... print(key)
... print(value)
... print()
...
model_0 vs model_1 # example1と同じ
model_0 vs model_2
model_1 vs model_2